﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    Layout = null;

    //公式部分
    List<dynamic> 招徕实施率 = new List<dynamic>();
    List<dynamic> 预约成功率 = new List<dynamic>();
    List<dynamic> 准时交车率 = new List<dynamic>();
    for (var dt = Model.BarModel.Start ?? DateTime.Now.AddMonths(-6); dt <= Model.BarModel.End; dt = dt.AddMonths(1))
    {
        var 当月考核目标 = Model.StandardConfigs.Where(o=>o.Month.Year==dt.Year && o.Month.Month==dt.Month).FirstOrDefault();
        var 月初数据 = Model.MonthTargets.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month).FirstOrDefault();
        var 每日数据 = Model.SADayDatas.Where(o => o.AddTime.Year == dt.Year && o.AddTime.Month == dt.Month);
        if(当月考核目标==null)
        {
            当月考核目标 =  new  S4Store.Domain.AfterSaleKpi.MonthStandardConfig();
        }
        
        if(月初数据==null)
        {
            月初数据 = new S4Store.Domain.AfterSaleKpi.AfterSaleServiceAdvisorMonthTarget();
        }

        招徕实施率.Add(new
        {
            时间 = dt,
            招徕实施率目标 = 当月考核目标.招徕实施率目标,
            招徕实施率实际 = Model.GetZLSSL(月初数据.EmployeeId,dt.Year,dt.Month)
        });

        预约成功率.Add(new
        {
            时间 = dt,
            预约成功率目标 = 当月考核目标.预约成功率目标,
            预约成功率实际 = Model.GetYYCGL(月初数据.EmployeeId, dt.Year, dt.Month)
        });

        准时交车率.Add(new
        {
            时间 = dt,
            准时交车率目标 = 当月考核目标.准时交车率目标,
            准时交车率实际 = Model.GetSAZSJCL(月初数据.EmployeeId, dt.Year, dt.Month)
        });
        
    }
    
    //图标部分
    S4Store.Models.Chart.Line ChartModel = new S4Store.Models.Chart.Line();
    ChartModel.IsRate = true;
    ChartModel.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel.YAxis = "招徕实施率";

    foreach (var item in 招徕实施率.GroupBy(o => o.时间))
    {
        ChartModel.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series = new S4Store.Models.Chart.ChartSeries();
    series.Name = "招徕实施率目标";
    foreach (var item in 招徕实施率)
    {
        series.Data.Add(item.招徕实施率目标);
    }
    ChartModel.Serieses.Add(series);
    S4Store.Models.Chart.ChartSeries series1 = new S4Store.Models.Chart.ChartSeries();
    series1.Name = "招徕实施率实际";
    foreach (var item in 招徕实施率)
    {
        series1.Data.Add(item.招徕实施率实际);
    }
    ChartModel.Serieses.Add(series1);
   


    //2
    S4Store.Models.Chart.Line ChartModel1 = new S4Store.Models.Chart.Line();
    ChartModel1.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel1.IsRate = true;
    ChartModel1.YAxis = "预约成功率";

    foreach (var item in 预约成功率.GroupBy(o => o.时间))
    {
        ChartModel1.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }

    S4Store.Models.Chart.ChartSeries series11 = new S4Store.Models.Chart.ChartSeries();
    series11.Name = "预约成功率目标";
    foreach (var item in 预约成功率)
    {
        series11.Data.Add(item.预约成功率目标);
    }
    ChartModel1.Serieses.Add(series11);

    S4Store.Models.Chart.ChartSeries series12 = new S4Store.Models.Chart.ChartSeries();
    series12.Name = "预约成功率实际";
    foreach (var item in 预约成功率)
    {
        series12.Data.Add(item.预约成功率实际);
    }
    ChartModel1.Serieses.Add(series12);

    
    
    //3
    S4Store.Models.Chart.Line ChartModel3 = new S4Store.Models.Chart.Line();
    ChartModel3.IsRate = true;
    ChartModel3.Colors = new List<string> { S4Store.Models.Chart.Color.Green, S4Store.Models.Chart.Color.Blue };
    ChartModel3.YAxis = "准时交车率";

    foreach (var item in 准时交车率.GroupBy(o => o.时间))
    {
        ChartModel3.XAxis.Add(item.Key.Year + "-" + item.Key.Month);
    }
    S4Store.Models.Chart.ChartSeries series31 = new S4Store.Models.Chart.ChartSeries();
    series31.Name = "准时交车率目标";
    foreach (var item in 准时交车率)
    {
        series31.Data.Add(item.准时交车率目标);
    }
    ChartModel3.Serieses.Add(series31);
    
    S4Store.Models.Chart.ChartSeries series32 = new S4Store.Models.Chart.ChartSeries();
    series32.Name = "准时交车率实际";
    foreach (var item in 准时交车率)
    {
        series32.Data.Add(item.准时交车率实际);
    }
    ChartModel3.Serieses.Add(series32);


<div style="height:100%; overflow:auto">

@Html.Action("ReportBar", "Common", Model.BarModel)
<div class="pagetitle">客户管理能力历史查询</div>
@Html.Partial("../Chart/Line", ChartModel)
<div></div>
@Html.Partial("../Chart/Line", ChartModel1)
<div></div>
@Html.Partial("../Chart/Line", ChartModel3)
</div>
}
